package chwgigs.swing.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class EX01_SungJukDAO implements EX01_ISungJukDAO {
private final String DRV = "oracle.jdbc.driver.OracleDriver";
private final String URL = "jdbc:oracle:thin:chwgigs/chwgigs@112.216.253.125:1521:xe";
private String insertSQL = "insert into EX01SungJuk values (exam.nextval, ?,?,?,?,?)";
private String selectSQL = "select * from EX01SungJuk order by mno desc" ;

	@Override
	public boolean insertSungJuk(EX01_SungJukVO sj) {
	 Connection conn =null;
	 PreparedStatement pstmt = null;
	 boolean result =false;
	 
	 
	 try {
		 conn= this.openDatabase();
		 pstmt = conn.prepareStatement(insertSQL);
		 pstmt.setInt(1,sj.getKor());
		 pstmt.setInt(2,sj.getEng());
		 
		 pstmt.setInt(3,sj.getMat());
		 pstmt.setInt(4,sj.getTot());
		 pstmt.setDouble(5,sj.getAvg());
		 pstmt.setString(6,sj.getGrd());
		 pstmt.executeUpdate();
		 result =true;
	  }catch (Exception ex) {
		  ex.printStackTrace();
     }finally {
    	 this.closeDatabase(conn,pstmt,null);
     }
	 return result;
	}
	
	private Connection openDatabase(){
		try {
			Class.forName(DRV);
			return DriverManager.getConnection(URL);
			}catch (Exception e) {
				e.printStackTrace();
			}
	       return null;
	       }
	private void closeDatabase(Connection c, PreparedStatement p, ResultSet r) {
	      if (r != null) try{r.close(); r = null;} catch(Exception e){}
	      if (p != null) try{p.close(); p = null;} catch(Exception e){}
	      if (c != null) try{c.close(); c = null;} catch(Exception e){}
	}
	
	
	
	
}//

